/*
===========================================================================
This source file is part of DyLab (Dynamic Laboratory)
For the latest info, see http://dylab.googlecode.com

Copyright (c) 2006-2008 Lukas Krejci
(krejci.lukas@volny.cz)

This file is part of DyLab.

    DyLab is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    DyLab is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with DyLab.  If not, see <http://www.gnu.org/licenses/>.
===========================================================================
*/

#ifndef __dylab_Ray3_h__
#define __dylab_Ray3_h__

//===========================================================================================
#include <dylab/utils/geometry/Vector3.h>

//===========================================================================================
namespace dylab {

    /** 
     *
     */
    class DYLAB_EXPORT Ray3 
    {
    public:
        /// rays corresponding to the 3 main axis
        static const Ray3 AXIS_X;
        static const Ray3 AXIS_Y;
        static const Ray3 AXIS_Z;
    protected:       
        /// start point of the ray
        Vector3 mStart;
        /// direction vector of the ray
        Vector3 mDirection;
    public:

        /**          
         */
        Ray3() 
                { }

        /**
        */
        Ray3(const Vector3 & _start, const Vector3 & _dir) 
            : mStart(_start), mDirection(_dir)
                { }

        /**
        */
        Ray3(const Ray3 & _ray) 
            : mStart(_ray.mStart), mDirection(_ray.mDirection)
                { }

        /** 
         */
        Ray3(const ArrayReal<6> & _v)
            : mStart(_v[0], _v[1], _v[2]), mDirection(_v[3], _v[4], _v[5])
                { } 

        /** 
         */
        Vector3 & start() 
                { return mStart; }

        /** 
         */
        const Vector3 & start() const
                { return mStart; }

        /** 
         */
        Vector3 & direction() 
                { return mDirection; }

        /** 
         */
        const Vector3 & direction() const
                { return mDirection; }

        /**
        */
        operator String() const                
				{ return String::fmt("%1% %2%", mStart, mDirection); }
    };

    //===========================================================================================    
    inline std::ostream & operator << (std::ostream & _os, const Ray3 & _o)
            { return _os << String(_o); }

    //===========================================================================================
    template <>
        inline Ray3 TypeParser::parse(const String & _string)
            { return Ray3(ArrayReal<6>::parse(_string)); }
    template <>
        inline Ray3 TypeParser::parse(const String & _string, const Ray3 & _defaultValue)
            {
                try { return TypeParser::parse<Ray3>(_string); }
                catch (EInvalidFormat &) { return _defaultValue; }
            }
    template <>
        inline String String::fmt(const Ray3 & _value)
            { return String(_value); }
}

//===========================================================================================
#endif // __dylab_Ray3_h__
